package com.pengshun.modules.api.order.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.coal.validator.Third;
import com.pengshun.modules.api.order.service.MerchantOrderService;
import com.pengshun.modules.api.order.service.dto.MerchantOrderDto;
import com.pengshun.modules.api.order.service.dto.OrderAllotTransportDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.ReslutView;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/2/20
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "卖家家订单管理")
@RequestMapping("/api/merchant/order")
@ApiIgnore
public class MerchantOrderController {

    private final MerchantOrderService merchantOrderService;

    @ApiOperation(value = "订单确认")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderStatus", value = " 3确认", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "freight", value = "运费", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "totalFreight", value = "总运费", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/sure", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult sure(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) MerchantOrderDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = merchantOrderService.sure(para);
        return res;
    }

    @ApiOperation(value = "订单/拒绝/取消")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderStatus", value = "2用户取消 4拒绝", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "cause", value = "拒绝取消原因", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/update", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) MerchantOrderDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = merchantOrderService.update(para);
        return res;
    }
    @ApiOperation(value = "商户删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/delete", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult delete(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) MerchantOrderDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = merchantOrderService.delete(para);
        return res;
    }

    @ApiOperation(value = "商家订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1待确认、3待支付、6待发货,7已完成", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/merchant-list", produces = "application/json; charset=utf-8")
    @Authorization
    @JsonView(ReslutView.aView.class)
    public BaseResult merchantList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) MerchantOrderDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = merchantOrderService.selectMerchantOrderList(para);
        return res;
    }

    @ApiOperation(value = "商户确认到货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/over", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult over(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) MerchantOrderDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = merchantOrderService.over(para);
        return res;
    }
}
